unit WaitUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TWaitDialogForm = class(TForm)
    grp1: TGroupBox;
    lblTitle: TLabel;
    lblCaption: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure ShowWaitDialog(const Title: string; const TextCaption: string);
procedure HideWaitDialog;
procedure UpdateTitle(const Title: string);
procedure UpdateCaption(const TextCaption: string);

implementation

{$R *.dfm}

var
  WaitDialogForm: TWaitDialogForm = nil;
  FormList: Pointer;

procedure ShowWaitDialog(const Title: string; const TextCaption: string);
begin
  if not Assigned(WaitDialogForm) then
    WaitDialogForm := TWaitDialogForm.Create(Application.MainForm)
  else
    WaitDialogForm.BringToFront;
  WaitDialogForm.lblTitle.Caption := Title;
  WaitDialogForm.lblCaption.Caption := TextCaption;

  WaitDialogForm.Show;

  FormList := DisableTaskWindows(WaitDialogForm.Handle);
  WaitDialogForm.Update;
end;

procedure HideWaitDialog;
begin
  if not Assigned(WaitDialogForm) then Exit;

  EnableTaskWindows(FormList);
  
  WaitDialogForm.Hide;
  Application.ProcessMessages;
  WaitDialogForm.Free;
  WaitDialogForm := nil;
end;

procedure UpdateTitle(const Title: string);
begin
  if Assigned(WaitDialogForm) then
  begin
    WaitDialogForm.lblTitle.Caption := Title;
    WaitDialogForm.Update;
    Application.ProcessMessages;
  end;
end;

procedure UpdateCaption(const TextCaption: string);
begin
  if Assigned(WaitDialogForm) then
  begin
    WaitDialogForm.lblCaption.Caption := TextCaption;
    WaitDialogForm.Update;
    Application.ProcessMessages;
  end;
end;

end.
